package com.yc.jpyy.mobile.controller;

import java.io.BufferedInputStream;
import java.io.BufferedReader;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.UnsupportedEncodingException;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.Map;
import java.util.UUID;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import com.etrans.ecpm.impl.RdtIntfWebImpl;
import com.etrans.ecpm.intf.IRdtIntf;
import com.etrans.ecpm.intf.TCmdReply;
import com.etrans.ecpm.intf.TCmdSendResp;
import com.etrans.ecpm.intf.TCmdStepInfo;
import com.etrans.ecpm.intf.UReqObj;
import com.yc.jpyy.base.bean.RestResponse;
import com.yc.jpyy.base.config.Config;
import com.yc.jpyy.base.controller.BaseController;
import com.yc.jpyy.mobile.dao.BizDao;

@Controller
@RequestMapping(value = "/command")
public class CommandController extends BaseController{
	
	@Autowired
	private BizDao bizDao;
	private static Logger logger = LoggerFactory.getLogger(CommandController.class);
	final static IRdtIntf intf = new RdtIntfWebImpl();
	static{
		//String host = "27.188.64.102";
		//String host = "172.31.0.16";
		//String host = "111.75.240.81";
		String host = "172.0.50.45";
        try {
        	/*intf.setup(
			        host+":16389:foobared",
			        host+":16379:foobared",
			        host+":16389:foobared",
			        host+":16379:foobared"
			);*/
			intf.setup(
			        host+":6389:foobared",
			        host+":6379:foobared",
			        host+":6389:foobared",
			        host+":6379:foobared"
			);
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	
	/*
	 * 文本信息下发
	 */
	@SuppressWarnings("finally")
	@RequestMapping(value = "/conmandTxtInfo", method = RequestMethod.POST, 
	                produces = "application/json; charset=utf-8")
	public @ResponseBody String conmandInfo(String text,int vehicleId)
			throws UnsupportedEncodingException {
		RestResponse response = new RestResponse();
		try {
			//标识符
	        //String commno = "100100900003";
			//String commno = "100900010001";
	        int vehicle_id = vehicleId;
	        //根据 vehicle_id查询terminal_id，terminalType
	        Map<String, Object> map = bizDao.getVehicleInfo(vehicleId);
	        int terminal_id = (int) map.get("TerminalID");
	        int terminalType = (int) map.get("terminalType");
	        String commno = (String) map.get("CommNO");
	        //文本下发消息ID
	        int cmdId = 0x8300;
	        //文本下发消息体
	        String args = "2,0,0,1,0," + text;
	        response = commandInfo(response, commno, vehicle_id, terminal_id,
					terminalType, cmdId, args);
		} catch (Exception e) {
			logger.info("conmandTxtInfo："+ e.toString());
			response.setErrorcode(1);
			response.setMessage("下发失败！");
		} finally {
			return response.toJSON();
		}
	}

	
	/*
	 * 司机信息下发
	 */
	@SuppressWarnings("finally")
	@RequestMapping(value = "/conmandDriverPicInfo", method = RequestMethod.POST, 
	                produces = "application/json; charset=utf-8")
	public @ResponseBody String conmandDriverPicInfo(String certiNumber,int vehicleId)
			throws UnsupportedEncodingException {
		RestResponse response = new RestResponse();
		try {
	        //String commno = "100100900003";
	        int vehicle_id = vehicleId;
	        //根据 vehicle_id查询terminal_id，terminalType
	        Map<String, Object> map = bizDao.getVehicleInfo(vehicleId);
	        int terminal_id = (int) map.get("TerminalID");
	        int terminalType = (int) map.get("terminalType");
	        String commno = (String) map.get("CommNO");
	        //自定义协议文本、图片下发
	        int cmdId = 0xA101;
	        //下发消息体(URL)
	        String args = Config.getDriverInfoURL() + certiNumber;
	        response = commandInfo(response, commno, vehicle_id, terminal_id,
					terminalType, cmdId, args);
		} catch (Exception e) {
			logger.info("conmandDriverPicInfo："+ e.toString());
			response.setErrorcode(1);
			response.setMessage("下发失败！");
		} finally {
			return response.toJSON();
		}
	}
	
	/*
	 * 计价器控制指令下发
	 */
	@SuppressWarnings("finally")
	@RequestMapping(value = "/conmandMeterInfo", method = RequestMethod.POST, 
	                produces = "application/json; charset=utf-8")
	public @ResponseBody String conmandMeterInfo(int flag,int vehicleId,String lockOrOpenTime)
			throws UnsupportedEncodingException {
		RestResponse response = new RestResponse();
		try {
			//String commno = "100900010001";
	        int vehicle_id = vehicleId;
	        //根据 vehicle_id查询terminal_id，terminalType
	        Map<String, Object> map = bizDao.getVehicleInfo(vehicleId);
	        int terminal_id = (int) map.get("TerminalID");
	        int terminalType = (int) map.get("terminalType");
	        String commno = (String) map.get("CommNO");
	        DateTimeFormatter dtf1 = DateTimeFormatter.ofPattern("yyyyMMddHH");
	        DateTimeFormatter dtf2 = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
	        //自定义协议文本、图片下发
	        int cmdId;
	        //下发消息体(URL) 
	        String args;
	        if(flag == 1){
	        	cmdId= 0xA110; //定时锁计价器
	        	LocalDateTime ldt = LocalDateTime.parse(lockOrOpenTime,dtf2);
	        	args = dtf1.format(ldt);
	        }else if(flag == 2){
	        	cmdId= 0xA111;  //定时解锁计价器
	        	LocalDateTime ldt = LocalDateTime.parse(lockOrOpenTime,dtf2);
	        	args = dtf1.format(ldt);
	        }else if(flag == 3){
	        	cmdId= 0xA112;  //（该指令锁计价器只能通过手动进行开锁）定时物理解锁
	        	LocalDateTime ldt = LocalDateTime.parse(lockOrOpenTime,dtf2);
	        	args = dtf1.format(ldt);
	        }else if(flag == 4){
	        	cmdId= 0xA110;  //立即锁
	        	args = "0000000000";
	        }else if(flag == 5){
	        	cmdId= 0xA111;  //立即开
	        	args = "0000000000";
	        }else{
	        	cmdId= 0xA112;  //物理立即解锁
	        	args = "0000000000";
	        }
	        response = commandInfo(response, commno, vehicle_id, terminal_id,
					terminalType, cmdId, args);
		} catch (Exception e) {
			logger.info("conmandDriverPicInfo："+ e.toString());
			response.setErrorcode(1);
			response.setMessage("下发失败！");
		} finally {
			return response.toJSON();
		}
	}
	

	/*
	 * 新计价器远程开锁下发指令
	 */
	@SuppressWarnings("finally")
	@RequestMapping(value = "/conmandMeterUnlock", method = RequestMethod.POST, 
	                produces = "application/json; charset=utf-8")
	public @ResponseBody String conmandMeterUnlock(int flag,String count,int vehicleId,String lockOrOpenTime)
			throws UnsupportedEncodingException {
		RestResponse response = new RestResponse();
		try {
	        int vehicle_id = vehicleId;
	        //根据 vehicle_id查询terminal_id，terminalType,common
	        Map<String, Object> map = bizDao.getVehicleInfo(vehicleId);
	        int terminal_id = (int) map.get("TerminalID");
	        int terminalType = (int) map.get("terminalType");
	        String commno = (String) map.get("CommNO");
	        DateTimeFormatter dtf = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
	        //自定义计价器开或锁
	        int cmdId = 0x8C00;
	        //下发消息体
	        String args = "";
	        if(flag == 1){  //开机
	        	args = "0";
	        }else if(flag == 2){//时间控制锁
	        	count = "0";
	        	args = "1;" + count + ";" + lockOrOpenTime;
	        }else if(flag == 3){//次数控制锁
	        	LocalDateTime now = LocalDateTime.now();
	        	lockOrOpenTime = now.format(dtf);
	        	args = "2;" + count + ";" + lockOrOpenTime;
	        }else if(flag == 4){//锁机
	        	args = "3";
	        }
	        response = commandInfo(response, commno, vehicle_id, terminal_id,
					terminalType, cmdId, args);
		} catch (Exception e) {
			logger.info("conmandMeterUnlock："+ e.toString());
			response.setErrorcode(1);
			response.setMessage("下发失败！");
		} finally {
			return response.toJSON();
		}
	}
	
	/*
	 * 905协议报警指令下发
	 */
	@SuppressWarnings("finally")
	@RequestMapping(value = "/conmandAlarm", method = RequestMethod.POST, 
	                produces = "application/json; charset=utf-8")
	public @ResponseBody String conmandAlarm(int vehicleId,int cmdId)
			throws UnsupportedEncodingException {
		RestResponse response = new RestResponse();
		try {
	        int vehicle_id = vehicleId;
	        //根据 vehicle_id查询terminal_id，terminalType,common
	        Map<String, Object> map = bizDao.getVehicleInfo(vehicleId);
	        int terminal_id = (int) map.get("TerminalID");
	        int terminalType = (int) map.get("terminalType");
	        String commno = (String) map.get("CommNO");
	        //消息体为空
	        String args = "";
	        response = commandInfo(response, commno, vehicle_id, terminal_id,
					terminalType, cmdId, args);
		} catch (Exception e) {
			logger.info("conmandAlarm："+ e.toString());
			response.setErrorcode(1);
			response.setMessage("下发失败！");
		} finally {
		return response.toJSON();
		}
	}
	
	
	/*
	 * 808协议报警指令下发
	 */
	@SuppressWarnings("finally")
	@RequestMapping(value = "/conmandAlarms", method = RequestMethod.POST, 
	                produces = "application/json; charset=utf-8")
	public @ResponseBody String conmandAlarms(int vehicleId,String args)
			throws UnsupportedEncodingException {
		RestResponse response = new RestResponse();
		try {
	        int vehicle_id = vehicleId;
	        //根据 vehicle_id查询terminal_id，terminalType,common
	        Map<String, Object> map = bizDao.getVehicleInfo(vehicleId);
	        int terminal_id = (int) map.get("TerminalID");
	        int terminalType = (int) map.get("terminalType");
	        String commno = (String) map.get("CommNO");
	        int cmdId =  0x8203;
	        response = commandInfo(response, commno, vehicle_id, terminal_id,
					terminalType, cmdId, args);
		} catch (Exception e) {
			logger.info("conmandAlarm："+ e.toString());
			response.setErrorcode(1);
			response.setMessage("下发失败！");
		} finally {
		return response.toJSON();
		}
	}
	
	
	/*
	 * 费率指令下发
	 */
	@SuppressWarnings("finally")
	@RequestMapping(value = "/conmandFee", method = RequestMethod.POST, 
	                produces = "application/json; charset=utf-8")
	public @ResponseBody String conmandFee(int vehicleId)
			throws UnsupportedEncodingException {
		RestResponse response = new RestResponse();
		try {
	        int vehicle_id = vehicleId;
	        //根据 vehicle_id查询terminal_id，terminalType,common
	        Map<String, Object> map = bizDao.getVehicleInfo(vehicleId);
	        int terminal_id = (int) map.get("TerminalID");
	        int terminalType = (int) map.get("terminalType");
	        String commno = (String) map.get("CommNO");
	        //自定义费率控制
	        int cmdId = 0x8C01;
	        //获取费率的加密内容（从文件中）
	        String url = CommandController.class.getClassLoader().getResource("ScretFee").getPath() +"/2.10-10.0.bin";
	        String content = bytesToHexString(toByteArray(url));
	        System.out.print(content);
	        //下发消息体
	        String args = content;
	        response = commandInfo(response, commno, vehicle_id, terminal_id,
					terminalType, cmdId, args);
		} catch (Exception e) {
			logger.info("conmandFee："+ e.toString());
			response.setErrorcode(1);
			response.setMessage("下发失败！");
		} finally {
			return response.toJSON();
		}
	}
	
	
	/**
	 * @param response
	 * @param commno
	 * @param vehicle_id
	 * @param terminal_id
	 * @param terminalType
	 * @param cmdId
	 * @param args
	 * @throws Exception
	 */
	/*private RestResponse commandInfo(RestResponse response, String commno,
			int vehicle_id, int terminal_id, int terminalType, int cmdId,
			String args) throws Exception {
		UUID uuid = UUID.randomUUID();
		long send_time = System.currentTimeMillis();
		UReqObj req_obj = new UReqObj(uuid, send_time, 197, vehicle_id, terminal_id, terminalType, "100100900003", cmdId, args);
		//100100900003
		//UReqObj req_obj = new UReqObj(UUID.randomUUID(), System.currentTimeMillis(), 197, 2,69929, 950, "100900010001", 0x8300, args) ;
		String req_key = ShortUUID.uuidToStr(req_obj.getUuid());
		intf.sendCMDAsyn(req_obj, new CallBack() {
				public void onCompletion(TCmdSendResp resp) {
					if(null == resp) {
			        	logger.info("没有获取到回复对象");
			        	return ;
			        }
					try {
						TCmdStepInfo stepInfo = intf.getCmdStepInfo(req_obj.getUuid(), 30);
						TCmdReply reply = null;
						if (stepInfo.hasReply()) {
						    reply = intf.getReply(req_obj.getMType(), req_obj.getMCode(), req_obj.getCmd(), resp.getCmdPkgSeq(), 30);
						    if (null != reply) {
						    	logger.info("收到指令回复：{}-{}",req_obj.getMCode(),req_key);
						    	response.setErrorcode(0);
							    response.setMessage(reply.getReplyMsg());
						    }else {
						    	logger.info("等待终端应答超时：{}",req_obj.getMCode());
						    	response.setErrorcode(1);
							    response.setMessage("等待终端应答超时！");
						    }
						}else {
							 logger.info("终端没有回复：{}",req_obj.getMCode());
							 response.setErrorcode(1);
							 response.setMessage("无reply");
						}
					} catch (Exception e) {
						e.printStackTrace();
					}
				}
			});
		return response;
	}*/
	
	/*
	 * 拍照指令下发
	 */
	@SuppressWarnings("finally")
	@RequestMapping(value = "/conmandTakePhoto", method = RequestMethod.POST, 
	                produces = "application/json; charset=utf-8")
	public @ResponseBody String conmandTakePhoto(String text,int vehicleId)
			throws UnsupportedEncodingException {
		RestResponse response = new RestResponse();
		try {
	        int vehicle_id = vehicleId;
	        //根据 vehicle_id查询terminal_id，terminalType
	        Map<String, Object> map = bizDao.getVehicleInfo(vehicleId);
	        int terminal_id = (int) map.get("TerminalID");
	        int terminalType = (int) map.get("terminalType");
	        String commno = (String) map.get("CommNO");
	        //拍照指令ID
	        int cmdId = 0x8801;
	        //拍照下发消息体
	        //String args = "010001000301010188111188";
	        String args = "1,1,0,0,1,1,0,0,0,0";
	        response = commandInfo(response, commno, vehicle_id, terminal_id,
					terminalType, cmdId, args);
		} catch (Exception e) {
			logger.info("conmandTakePhoto："+ e.toString());
			response.setErrorcode(1);
			response.setMessage("下发失败！");
		} finally {
			return response.toJSON();
		}
	}
	/**
	 * @param response
	 * @param commno
	 * @param vehicle_id
	 * @param terminal_id
	 * @param terminalType
	 * @param cmdId
	 * @param args
	 * @throws Exception
	 */
	private RestResponse commandInfo(RestResponse response, String commno,
			int vehicle_id, int terminal_id, int terminalType, int cmdId,
			String args) throws Exception {
		UUID uuid = UUID.randomUUID();
		long send_time = System.currentTimeMillis();
		UReqObj req_obj = new UReqObj(uuid, send_time, 197, vehicle_id, terminal_id, terminalType, commno, cmdId, args);
		TCmdSendResp resp = intf.sendCMD(req_obj);
		if (null == resp) {
		    logger.error("not get response.");
		    response.setErrorcode(1);
			response.setMessage("未获取到应答！");
		    return response;
		}
		logger.info("cmdResp={}, hint={}", resp.getReqUUID().toString(), resp.getRespType().getName());
		TCmdStepInfo stepInfo;

		stepInfo = intf.getCmdStepInfo(uuid, 5);
		logger.info("stepInfo={}", stepInfo);

		TCmdReply reply = null;
		if (stepInfo.hasReply()) {
		    reply = intf.getReply(terminalType, commno, cmdId, resp.getCmdPkgSeq(), 40);
		    if (null == reply){
		    	logger.info("等待终端应答超时");
		    	response.setErrorcode(1);
			    response.setMessage("等待终端应答超时！");
			    return response;
		    }else{
		    	logger.info("cmdReply: {}, {}", reply.getReplyBody(), reply.getReplyMsg());
		    	response.setErrorcode(0);
			    response.setMessage(reply.getReplyMsg());
			    response.setMessageBody(reply.getReplyBody());
			    return response;
		    }
		} else {
		    logger.info("无reply");
		    response.setErrorcode(1);
		    response.setMessage("无reply");
		    return response;
		}
	}

	
	 String getFileContent(String url) throws Exception{
        File f = new File(url);
        FileReader reader = new FileReader(f);//定义一个fileReader对象，用来初始化BufferedReader
		//FileInputStream fs=new FileInputStream(url);
        //InputStreamReader reader = new InputStreamReader(fs,"UTF-8");
        BufferedReader bReader = new BufferedReader(reader);//new一个BufferedReader对象，将文件内容读取到缓存
        StringBuilder sb = new StringBuilder();//定义一个字符串缓存，将字符串存放缓存中
        String s = "";
        while ((s = bReader.readLine()) != null) {//逐行读取文件内容，不读取换行符和末尾的空格
            sb.append(s);//将读取的字符串累加存放在缓存中
        }
        bReader.close();
        //String str = sb.toString();
        //转成ASCII码
        /*StringBuilder newsb = new StringBuilder();
        char[] ch = str.toCharArray();
        for (int i = 0; i < ch.length; i++) {
        	newsb.append(Integer.valueOf(ch[i]).intValue());// 不加空格
        }*/
        //截取前512字节
        //String str512 = bSubstring(newsb.toString(), 512);
        //String str512s = bSubstring(str, 512);
        //转16进制
        //String result = strTo16(str512);
        String results =  readFile(url);
        //String result = strTo16(results);
		return results;
	}
	 
	 public static String readFile(String filePath) {
	        String fileContent = "";
	        try {
	            File f = new File(filePath);
	            if (f.isFile() && f.exists()) {
	                InputStreamReader read = new InputStreamReader(new FileInputStream(f), "UTF-8");
	                BufferedReader reader = new BufferedReader(read);
	                String line;
	                while ((line = reader.readLine()) != null) {
	                    fileContent += line;
	                }
	                read.close();
	            }
	        } catch (Exception e) {
	            System.out.println("读取文件内容操作出错");
	            e.printStackTrace();
	        }
	        return fileContent;
	    }
	 
	 
	 /*
	  * 截取字节数
	  */
	 
	 public static String bSubstring(String s, int length) throws Exception
	    {

	        byte[] bytes = s.getBytes("Unicode");
	        int n = 0; // 表示当前的字节数
	        int i = 2; // 要截取的字节数，从第3个字节开始
	        for (; i < bytes.length && n < length; i++)
	        {
	            // 奇数位置，如3、5、7等，为UCS2编码中两个字节的第二个字节
	            if (i % 2 == 1)
	            {
	                n++; // 在UCS2第二个字节时n加1
	            }
	            else
	            {
	                // 当UCS2编码的第一个字节不等于0时，该UCS2字符为汉字，一个汉字算两个字节
	                if (bytes[i] != 0)
	                {
	                    n++;
	                }
	            }
	        }
	        // 如果i为奇数时，处理成偶数
	        if (i % 2 == 1)

	        {
	            // 该UCS2字符是汉字时，去掉这个截一半的汉字
	            if (bytes[i - 1] != 0)
	                i = i - 1;
	            // 该UCS2字符是字母或数字，则保留该字符
	            else
	                i = i + 1;
	        }

	        return new String(bytes, 0, i, "Unicode");
	    }
	 
	 
	 /**
	  * 字符串转化成为16进制字符串
	  * @param s
	  * @return
	  */
	 public static String strTo16(String s) {
	     String str = "";
	     for (int i = 0; i < s.length(); i++) {
	         int ch = (int) s.charAt(i);
	         String s4 = Integer.toHexString(ch);
	         str = str + s4;
	     }
	     return str;
	 }
	 
	 //转16进制
	 public static String bytesToHexString(byte[] src){
	        StringBuilder stringBuilder = new StringBuilder("");
	        if (src == null || src.length <= 0) {
	            return null;
	        }
	        for (int i = 0; i < src.length; i++) {
	            int v = src[i] & 0xFF;
	            String hv = Integer.toHexString(v);
	            if (hv.length() < 2) {
	                stringBuilder.append(0);
	            }
	            stringBuilder.append(hv);
	        }
	        return stringBuilder.toString();
	    }
	    public static byte[] toByteArray(String filename) throws IOException {

	        File f = new File(filename);
	        if (!f.exists()) {
	            throw new FileNotFoundException(filename);
	        }
	        //字节数组输出流在内存中创建一个字节数组缓冲区
	        ByteArrayOutputStream bos = new ByteArrayOutputStream((int) f.length());
	        BufferedInputStream in = null;
	        try {
	            in = new BufferedInputStream(new FileInputStream(f));
	            int buf_size = 1024;
	            byte[] buffer = new byte[buf_size];
	            int len = 0;
	            while (-1 != (len = in.read(buffer, 0, buf_size))) {
	                bos.write(buffer, 0, len);
	            }
	            //创建一个新分配的字节数组。数组的大小是当前输出流的大小，内容是当前输出流的拷贝
	            return bos.toByteArray();
	        } catch (IOException e) {
	            e.printStackTrace();
	            throw e;
	        } finally {
	            try {
	                in.close();
	            } catch (IOException e) {
	                e.printStackTrace();
	            }
	            bos.close();
	        }
	    }
	   
	    
	    /*
		 * 指令位置查询
		 */
		@SuppressWarnings("finally")
		@RequestMapping(value = "/conmandLocation", method = RequestMethod.POST, 
		                produces = "application/json; charset=utf-8")
		public @ResponseBody String conmandLocation(String text,int vehicleId)
				throws UnsupportedEncodingException {
			RestResponse response = new RestResponse();
			try {
		        int vehicle_id = vehicleId;
		        //根据 vehicle_id查询terminal_id，terminalType
		        Map<String, Object> map = bizDao.getVehicleInfo(vehicleId);
		        int terminal_id = (int) map.get("TerminalID");
		        int terminalType = (int) map.get("terminalType");
		        String commno = (String) map.get("CommNO");
		        //位置获取指令ID
		        int cmdId = 0x8201;
		        //消息体为空
		        String args = "";
		        response = commandInfo(response, commno, vehicle_id, terminal_id,
						terminalType, cmdId, args);
			} catch (Exception e) {
				logger.info("conmandLocation："+ e.toString());
				response.setErrorcode(1);
				response.setMessage("下发失败！");
			} finally {
				return response.toJSON();
			}
		}
		
		
		 /*
		 * 指令设备重启
		 */
		@SuppressWarnings("finally")
		@RequestMapping(value = "/conmandReset", method = RequestMethod.POST, 
		                produces = "application/json; charset=utf-8")
		public @ResponseBody String conmandReset(String text,int vehicleId)
				throws UnsupportedEncodingException {
			RestResponse response = new RestResponse();
			try {
		        int vehicle_id = vehicleId;
		        //根据 vehicle_id查询terminal_id，terminalType
		        Map<String, Object> map = bizDao.getVehicleInfo(vehicleId);
		        int terminal_id = (int) map.get("TerminalID");
		        int terminalType = (int) map.get("terminalType");
		        String commno = (String) map.get("CommNO");
		        //位置获取指令ID
		        int cmdId = 0x8105;
		        //消息体为空
		        String args = "1,4";
		        response = commandInfo(response, commno, vehicle_id, terminal_id,
						terminalType, cmdId, args);
			} catch (Exception e) {
				logger.info("conmandReset："+ e.toString());
				response.setErrorcode(1);
				response.setMessage("下发失败！");
			} finally {
				return response.toJSON();
			}
		}
	    
}
